<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2019/1/4
 * Time: 11:26
 */

namespace app\api\model;


class WebSubelement extends BaseModel
{
    protected $autoWriteTimestamp = true;

    /**
     * 与third_app为一对一关系
     * @return \think\model\relation\BelongsTo
     */
    public function thirdapp(){
        return $this->belongsTo('ThirdApp','t_id','id');
    }

    /**
     * 添加子元素
     * @param $data
     * @return array|false
     */
    public static function addSubWeb($data){
        $subelement = new WebSubelement();
        return $subelement->saveAll($data);
    }
    /**
     *获取所有子元素
     * @return false|\PDOStatement|string|\think\Collection
     */
    public static function deleteSubWeb($uid){
        return self::where('t_id','=',$uid)->delete();
    }
    /**
     *
     * 获取子元素
     * @param $uid
     * @param $sub_id
     * @return array|false|\PDOStatement|string|\think\Model
     */
    public static function getSubWeb($uid,$sub_id,$type){
        $info =  self::where('t_id','=',$uid)
            ->where('sub_id','=',$sub_id)
            ->where('style','=',$type)
            ->with(['thirdapp'])
            ->find();
      $info->thirdapp->visible(['name','sub_name']);
      return $info;

    }
}